package com.weme.common.view

import android.content.Context
import android.util.AttributeSet
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient

class CustomWebView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr) {

    init {
        initWebViewSettings()
    }

    private fun initWebViewSettings() {
        val settings: WebSettings = this.settings

        // 启用 JavaScript
        settings.javaScriptEnabled = true

        // 禁用缩放
        settings.setSupportZoom(false)
        settings.builtInZoomControls = false
        settings.displayZoomControls = false

        // 在 WebView 中打开链接，而不是跳转到浏览器
        webViewClient = WebViewClient()

        // 获取页面标题
        webChromeClient = object : WebChromeClient() {
            override fun onReceivedTitle(view: WebView?, title: String?) {
                super.onReceivedTitle(view, title)
                // 在这里处理页面标题
            }
        }
    }

    // 加载指定的 URL
    override fun loadUrl(url: String) {
        super.loadUrl(url)
    }
}
